package com.xcity.game.combat.skill.impl;

import com.alibaba.fastjson.annotation.JSONField;
import com.xcity.game.combat.Action;
import com.xcity.game.combat.ActionEffect;
import com.xcity.game.combat.CombatUtils;
import com.xcity.game.combat.buff.CombatBuff;
import com.xcity.game.combat.skill.CombatSkill;
import com.xcity.game.combat.unit.CombatUnit;
import com.xcity.game.common.GameStaticConfig;
import com.xcity.game.skill.Skill;

/**
 * 笑里藏刀<br/>
 * 对敌方随机一个目标造成{0=100#0}%技能伤害，并在接下来{1=2#0}个回合内造成每次{2=25#0}%的技能伤害
 * @author yang.li
 *
 */
public class COMBAT_SKILL_90084 extends CombatSkill {

	public COMBAT_SKILL_90084(Skill skill) {
		super(skill);
	}

	@Override
	public void calcDamage(Action action) {
		CombatUnit target = action.target.getUnitRandomly();
		if (target != null) {
			ActionEffect effect = action.addTarget(target);
			CombatUnit source = action.unit;
			target = effect.getUnit(); // 修正目标
			float rate = skill.getParameter(0) / GameStaticConfig.percentBase;
//			int damage = (int) (source.getMagicPower() * rate - CombatUtils.calcMagicDefenseReduceDamage(effect.getUnit()));
//			damage = CombatUtils.correctDamage(damage);
//			effect.effect(CombatAttribute.Type.HP, -damage);
			CombatUtils.calcMagicAttack(effect, rate);
			// debuff
			action.addBuff(new BUFF(skill, target, source));
		}
	}
	
	static class BUFF extends CombatBuff {
		CombatUnit source;
		Skill skill;
		float damageRate;
		public BUFF(Skill skill, CombatUnit owner, CombatUnit source) {
			super(null, owner, (int) skill.getParameter(1));
			this.source = source;
			this.skill = skill;
			this.damageRate = skill.getParameter(2) / GameStaticConfig.percentBase;
		}
		@Override
		public int getId() {
			return skill.getId();
		}
		@Override
		public void preAction(Action action) {
			active = true;
//			int damage = (int) (source.getMagicPower() * damageRate - CombatUtils.calcMagicDefenseReduceDamage(owner));
//			damage = CombatUtils.correctDamage(damage);
//			ActionEffect effect = action.addTarget(owner);
//			effect.effect(CombatAttribute.Type.HP, -damage);
			ActionEffect effect = action.addTarget(owner);
			CombatUtils.calcMagicAttack(effect, damageRate);
		}
		@Override
		@JSONField(serialize = false)
		public boolean isDebuff() {
			return true;
		}
	}
	
}
